# _*_ coding: utf-8 _*_
from odoo import models, fields, api


class PurchaseRequisition(models.Model):
    _inherit = "purchase.requisition"
    _order = "sequence, id desc"

    sequence = fields.Integer(string="Sequence", default=100)
    emergent = fields.Boolean(string="Emergent", default=False)

    @api.multi
    def toggle_emergent(self):
        for record in self:
            record.emergent = not record.emergent
            if record.emergent:
                record.sequence = 1
            else:
                record.sequence = 100
